import java.util.ArrayList;

import org.htmlparser.Node;
import org.htmlparser.NodeFilter;
import org.htmlparser.Parser;
import org.htmlparser.Tag;
import org.htmlparser.filters.StringFilter;
import org.htmlparser.tags.HeadingTag;
import org.htmlparser.tags.LinkTag;
import org.htmlparser.tags.TitleTag;
import org.htmlparser.util.NodeList;
import org.htmlparser.visitors.NodeVisitor;


public class webParser {

	public static ArrayList<String> ProjectNameList = new ArrayList<String>();
	public static ArrayList<String> HomePageList = new ArrayList<String>();
	public static ArrayList<String> ShortDescrList = new ArrayList<String>();
	public static ArrayList<String> LicenseList = new ArrayList<String>();
	public static ArrayList<String> LanguageList = new ArrayList<String>();
	public static ArrayList<String> CategoryList = new ArrayList<String>();
	public static ArrayList<String> IssueList = new ArrayList<String>();
	public static ArrayList<String> MailingList = new ArrayList<String>();
	int tmp;
	private Visitors visitor = new Visitors();
	private String projectName = null;
	
	
	private void generateProjectName(){
		
		for(int i = 0; i < ProjectNameList.size(); i++)
			System.out.println(ProjectNameList.get(i));
		
		projectName = ProjectNameList.get(0);
		if(ProjectNameList.size() == 2){
			if(ProjectNameList.get(0).contains(ProjectNameList.get(1)))
				projectName = ProjectNameList.get(1);
		}

		System.out.println("---Project Name: " + projectName);
	}
	
	private void generateMailingList(){
		
		for(int i = 0; i < MailingList.size(); i++)
			System.out.println(MailingList.get(i));
	}
	
	private void generate(){
		//generateProjectName();
		generateMailingList();
	}
	
	
	public void traversal(String url){
		
		try{
			
			Parser parser = new Parser();
			parser.setURL(url);
			parser.setEncoding(parser.getEncoding());

			NodeFilter filter = new StringFilter("Mailing List");
			NodeList nodes = parser.extractAllNodesThatMatch(filter);
			
			if(nodes!=null) {
	            for (int i = 0; i < nodes.size(); i++) {
	                Node textnode = (Node) nodes.elementAt(i);
	                
	                tmp = textnode.getStartPosition();
	                System.out.println("getText:"+textnode.getText());
	                System.out.println("=================================================");
	            }
            }
			
			parser.visitAllNodesWith(visitor.test);
			generate();
			
		}catch( Exception e ) {}
	}
}
